.class public final Lcom/burstly/lib/network/beans/cookie/CookieManager;
.super Ljava/lang/Object;
.source "CookieManager.java"


# annotations
.annotation system Ldalvik/annotation/MemberClasses;
    value = {
        Lcom/burstly/lib/network/beans/cookie/CookieManager$DbSaveWorker;
    }
.end annotation


# static fields
.field static final LATCH:Ljava/util/concurrent/CountDownLatch; = null

.field static final LOG:Lcom/burstly/lib/util/LoggerExt; = null

.field private static final SAVE_QUEUE:Ljava/util/concurrent/Executor; = null

.field static final TAG:Ljava/lang/String; = "CookieManager"

.field static volatile sIsInitStarted:Z

.field static volatile sIsReady:Z

.field static sMemoryCookieStorage:Lcom/burstly/lib/network/beans/cookie/ICookieStorage;

.field static sSQLiteCookieStorage:Lcom/burstly/lib/network/beans/cookie/ICookieStorage;


# direct methods
.method static constructor <clinit>()V
    .locals 2

    .prologue
    .line 44
    invoke-static {}, Lcom/burstly/lib/util/LoggerExt;->getInstance()Lcom/burstly/lib/util/LoggerExt;

    move-result-object v0

    sput-object v0, Lcom/burstly/lib/network/beans/cookie/CookieManager;->LOG:Lcom/burstly/lib/util/LoggerExt;

    .line 49
    new-instance v0, Ljava/util/concurrent/CountDownLatch;

    const/4 v1, 0x1

    invoke-direct {v0, v1}, Ljava/util/concurrent/CountDownLatch;-><init>(I)V

    sput-object v0, Lcom/burstly/lib/network/beans/cookie/CookieManager;->LATCH:Ljava/util/concurrent/CountDownLatch;

    .line 54
    new-instance v0, Lcom/burstly/lib/network/beans/cookie/CookieManager$1;

    invoke-direct {v0}, Lcom/burstly/lib/network/beans/cookie/CookieManager$1;-><init>()V

    invoke-static {v0}, Ljava/util/concurrent/Executors;->newSingleThreadExecutor(Ljava/util/concurrent/ThreadFactory;)Ljava/util/concurrent/ExecutorService;

    move-result-object v0

    sput-object v0, Lcom/burstly/lib/network/beans/cookie/CookieManager;->SAVE_QUEUE:Ljava/util/concurrent/Executor;

    return-void
.end method

.method private constructor <init>()V
    .locals 0

    .prologue
    .line 87
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    .line 88
    return-void
.end method

.method private static checkManager()V
    .locals 2

    .prologue
    .line 122
    sget-boolean v0, Lcom/burstly/lib/network/beans/cookie/CookieManager;->sIsInitStarted:Z

    if-nez v0, :cond_0

    .line 123
    new-instance v0, Ljava/lang/RuntimeException;

    const-string v1, "Can not use CookieManager before it was initialized. Call CookieManager.initCookieManager() method first!"

    invoke-direct {v0, v1}, Ljava/lang/RuntimeException;-><init>(Ljava/lang/String;)V

    throw v0

    .line 126
    :cond_0
    return-void
.end method

.method static declared-synchronized destroy()V
    .locals 2

    .prologue
    .line 305
    const-class v1, Lcom/burstly/lib/network/beans/cookie/CookieManager;

    monitor-enter v1

    :try_start_0
    invoke-static {}, Lcom/burstly/lib/network/beans/cookie/CookieManager;->checkManager()V

    .line 306
    invoke-static {}, Lcom/burstly/lib/network/beans/cookie/CookieManager;->waitForReadyState()V

    .line 307
    const/4 v0, 0x0

    sput-boolean v0, Lcom/burstly/lib/network/beans/cookie/CookieManager;->sIsInitStarted:Z

    .line 308
    const/4 v0, 0x0

    sput-boolean v0, Lcom/burstly/lib/network/beans/cookie/CookieManager;->sIsReady:Z

    .line 309
    const/4 v0, 0x0

    sput-object v0, Lcom/burstly/lib/network/beans/cookie/CookieManager;->sSQLiteCookieStorage:Lcom/burstly/lib/network/beans/cookie/ICookieStorage;

    .line 310
    const/4 v0, 0x0

    sput-object v0, Lcom/burstly/lib/network/beans/cookie/CookieManager;->sMemoryCookieStorage:Lcom/burstly/lib/network/beans/cookie/ICookieStorage;
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0

    .line 311
    monitor-exit v1

    return-void

    .line 305
    :catchall_0
    move-exception v0

    monitor-exit v1

    throw v0
.end method

.method public static declared-synchronized getMemoryCookieStorage()Lcom/burstly/lib/network/beans/cookie/ICookieStorage;
    .locals 2

    .prologue
    .line 245
    const-class v1, Lcom/burstly/lib/network/beans/cookie/CookieManager;

    monitor-enter v1

    :try_start_0
    invoke-static {}, Lcom/burstly/lib/network/beans/cookie/CookieManager;->checkManager()V

    .line 246
    invoke-static {}, Lcom/burstly/lib/network/beans/cookie/CookieManager;->waitForReadyState()V

    .line 247
    sget-object v0, Lcom/burstly/lib/network/beans/cookie/CookieManager;->sMemoryCookieStorage:Lcom/burstly/lib/network/beans/cookie/ICookieStorage;
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0

    monitor-exit v1

    return-object v0

    .line 245
    :catchall_0
    move-exception v0

    monitor-exit v1

    throw v0
.end method

.method public static declared-synchronized getSQLiteCookieStorage()Lcom/burstly/lib/network/beans/cookie/ICookieStorage;
    .locals 2

    .prologue
    .line 233
    const-class v1, Lcom/burstly/lib/network/beans/cookie/CookieManager;

    monitor-enter v1

    :try_start_0
    invoke-static {}, Lcom/burstly/lib/network/beans/cookie/CookieManager;->checkManager()V

    .line 234
    invoke-static {}, Lcom/burstly/lib/network/beans/cookie/CookieManager;->waitForReadyState()V

    .line 235
    sget-object v0, Lcom/burstly/lib/network/beans/cookie/CookieManager;->sSQLiteCookieStorage:Lcom/burstly/lib/network/beans/cookie/ICookieStorage;
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0

    monitor-exit v1

    return-object v0

    .line 233
    :catchall_0
    move-exception v0

    monitor-exit v1

    throw v0
.end method

.method public static getValidCookies()[Lcom/burstly/lib/network/beans/cookie/CookieHolder;
    .locals 7

    .prologue
    .line 150
    invoke-static {}, Lcom/burstly/lib/network/beans/cookie/CookieManager;->checkManager()V

    .line 151
    invoke-static {}, Lcom/burstly/lib/network/beans/cookie/CookieManager;->waitForReadyState()V

    .line 152
    sget-object v6, Lcom/burstly/lib/network/beans/cookie/CookieManager;->sMemoryCookieStorage:Lcom/burstly/lib/network/beans/cookie/ICookieStorage;

    invoke-interface {v6}, Lcom/burstly/lib/network/beans/cookie/ICookieStorage;->getValidCookies()Ljava/util/Collection;

    move-result-object v2

    .line 153
    .local v2, cookiesInMemory:Ljava/util/Collection;,"Ljava/util/Collection<Lcom/burstly/lib/network/beans/cookie/CookieHolderWrapper;>;"
    invoke-interface {v2}, Ljava/util/Collection;->isEmpty()Z

    move-result v6

    if-nez v6, :cond_0

    .line 154
    invoke-interface {v2}, Ljava/util/Collection;->size()I

    move-result v6

    new-array v1, v6, [Lcom/burstly/lib/network/beans/cookie/CookieHolder;

    .line 155
    .local v1, cookies:[Lcom/burstly/lib/network/beans/cookie/CookieHolder;
    const/4 v4, 0x0

    .line 156
    .local v4, ind:I
    invoke-interface {v2}, Ljava/util/Collection;->iterator()Ljava/util/Iterator;

    move-result-object v3

    .local v3, i$:Ljava/util/Iterator;
    :goto_0
    invoke-interface {v3}, Ljava/util/Iterator;->hasNext()Z

    move-result v6

    if-eqz v6, :cond_1

    invoke-interface {v3}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Lcom/burstly/lib/network/beans/cookie/CookieHolderWrapper;

    .line 157
    .local v0, cookieHolderWrapper:Lcom/burstly/lib/network/beans/cookie/CookieHolderWrapper;
    add-int/lit8 v5, v4, 0x1

    .end local v4           #ind:I
    .local v5, ind:I
    invoke-virtual {v0}, Lcom/burstly/lib/network/beans/cookie/CookieHolderWrapper;->getCookie()Lcom/burstly/lib/network/beans/cookie/CookieHolder;

    move-result-object v6

    aput-object v6, v1, v4

    move v4, v5

    .end local v5           #ind:I
    .restart local v4       #ind:I
    goto :goto_0

    .line 161
    .end local v0           #cookieHolderWrapper:Lcom/burstly/lib/network/beans/cookie/CookieHolderWrapper;
    .end local v1           #cookies:[Lcom/burstly/lib/network/beans/cookie/CookieHolder;
    .end local v3           #i$:Ljava/util/Iterator;
    .end local v4           #ind:I
    :cond_0
    const/4 v1, 0x0

    :cond_1
    return-object v1
.end method

.method public static initCookieManager(Landroid/content/Context;)V
    .locals 3
    .parameter "context"

    .prologue
    .line 97
    sget-boolean v2, Lcom/burstly/lib/network/beans/cookie/CookieManager;->sIsInitStarted:Z

    if-nez v2, :cond_0

    .line 98
    const/4 v2, 0x1

    sput-boolean v2, Lcom/burstly/lib/network/beans/cookie/CookieManager;->sIsInitStarted:Z

    .line 99
    invoke-virtual {p0}, Landroid/content/Context;->getApplicationContext()Landroid/content/Context;

    move-result-object v0

    .line 100
    .local v0, applContext:Landroid/content/Context;
    new-instance v1, Ljava/lang/Thread;

    new-instance v2, Lcom/burstly/lib/network/beans/cookie/CookieManager$2;

    invoke-direct {v2, v0}, Lcom/burstly/lib/network/beans/cookie/CookieManager$2;-><init>(Landroid/content/Context;)V

    invoke-direct {v1, v2}, Ljava/lang/Thread;-><init>(Ljava/lang/Runnable;)V

    .line 112
    .local v1, initThread:Ljava/lang/Thread;
    const-string v2, "Cookie init thread."

    invoke-virtual {v1, v2}, Ljava/lang/Thread;->setName(Ljava/lang/String;)V

    .line 113
    invoke-virtual {v1}, Ljava/lang/Thread;->start()V

    .line 115
    .end local v0           #applContext:Landroid/content/Context;
    .end local v1           #initThread:Ljava/lang/Thread;
    :cond_0
    return-void
.end method

.method static declared-synchronized isInitialized()Z
    .locals 3

    .prologue
    .line 287
    const-class v2, Lcom/burstly/lib/network/beans/cookie/CookieManager;

    monitor-enter v2

    :try_start_0
    invoke-static {}, Lcom/burstly/lib/network/beans/cookie/CookieManager;->checkManager()V
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0
    .catch Ljava/lang/RuntimeException; {:try_start_0 .. :try_end_0} :catch_0

    .line 292
    :try_start_1
    invoke-static {}, Lcom/burstly/lib/network/beans/cookie/CookieManager;->waitForReadyState()V
    :try_end_1
    .catchall {:try_start_1 .. :try_end_1} :catchall_0

    .line 293
    const/4 v1, 0x1

    .local v0, e:Ljava/lang/RuntimeException;
    :goto_0
    monitor-exit v2

    return v1

    .line 289
    .end local v0           #e:Ljava/lang/RuntimeException;
    :catch_0
    move-exception v0

    .line 290
    .restart local v0       #e:Ljava/lang/RuntimeException;
    const/4 v1, 0x0

    goto :goto_0

    .line 287
    .end local v0           #e:Ljava/lang/RuntimeException;
    :catchall_0
    move-exception v1

    monitor-exit v2

    throw v1
.end method

.method public static saveCookies([Lcom/burstly/lib/network/beans/cookie/CookieHolder;)V
    .locals 9
    .parameter "newCookies"

    .prologue
    .line 211
    invoke-static {}, Lcom/burstly/lib/network/beans/cookie/CookieManager;->checkManager()V

    .line 212
    invoke-static {}, Lcom/burstly/lib/network/beans/cookie/CookieManager;->waitForReadyState()V

    .line 213
    if-eqz p0, :cond_0

    array-length v3, p0

    if-lez v3, :cond_0

    .line 214
    invoke-static {p0}, Ljava/util/Arrays;->asList([Ljava/lang/Object;)Ljava/util/List;

    move-result-object v2

    .line 216
    .local v2, inputCookies:Ljava/util/List;,"Ljava/util/List<Lcom/burstly/lib/network/beans/cookie/CookieHolder;>;"
    :try_start_0
    sget-object v3, Lcom/burstly/lib/network/beans/cookie/CookieManager;->sMemoryCookieStorage:Lcom/burstly/lib/network/beans/cookie/ICookieStorage;

    invoke-interface {v3, v2}, Lcom/burstly/lib/network/beans/cookie/ICookieStorage;->processCookies(Ljava/util/Collection;)V

    .line 217
    new-instance v0, Lcom/burstly/lib/network/beans/cookie/CookieManager$DbSaveWorker;

    sget-object v3, Lcom/burstly/lib/network/beans/cookie/CookieManager;->sSQLiteCookieStorage:Lcom/burstly/lib/network/beans/cookie/ICookieStorage;

    invoke-direct {v0, v2, v3}, Lcom/burstly/lib/network/beans/cookie/CookieManager$DbSaveWorker;-><init>(Ljava/util/List;Lcom/burstly/lib/network/beans/cookie/ICookieStorage;)V

    .line 218
    .local v0, dbSaveWorker:Ljava/lang/Runnable;
    sget-object v3, Lcom/burstly/lib/network/beans/cookie/CookieManager;->SAVE_QUEUE:Ljava/util/concurrent/Executor;

    invoke-interface {v3, v0}, Ljava/util/concurrent/Executor;->execute(Ljava/lang/Runnable;)V
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    .line 224
    .end local v0           #dbSaveWorker:Ljava/lang/Runnable;
    .end local v2           #inputCookies:Ljava/util/List;,"Ljava/util/List<Lcom/burstly/lib/network/beans/cookie/CookieHolder;>;"
    :cond_0
    :goto_0
    return-void

    .line 220
    .restart local v2       #inputCookies:Ljava/util/List;,"Ljava/util/List<Lcom/burstly/lib/network/beans/cookie/CookieHolder;>;"
    :catch_0
    move-exception v1

    .line 221
    .local v1, e:Ljava/lang/Exception;
    sget-object v3, Lcom/burstly/lib/network/beans/cookie/CookieManager;->LOG:Lcom/burstly/lib/util/LoggerExt;

    const-string v4, "CookieManager"

    const-string v5, "Exception during saving new cookies: {0}"

    const/4 v6, 0x1

    new-array v6, v6, [Ljava/lang/Object;

    const/4 v7, 0x0

    invoke-virtual {v1}, Ljava/lang/Exception;->getMessage()Ljava/lang/String;

    move-result-object v8

    aput-object v8, v6, v7

    invoke-virtual {v3, v4, v5, v6}, Lcom/burstly/lib/util/LoggerExt;->logError(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    goto :goto_0
.end method

.method static declared-synchronized setMemoryCookieStorage(Lcom/burstly/lib/network/beans/cookie/ICookieStorage;)V
    .locals 2
    .parameter "newMemoryCookieStorage"

    .prologue
    .line 273
    const-class v1, Lcom/burstly/lib/network/beans/cookie/CookieManager;

    monitor-enter v1

    :try_start_0
    invoke-static {}, Lcom/burstly/lib/network/beans/cookie/CookieManager;->checkManager()V

    .line 274
    invoke-static {}, Lcom/burstly/lib/network/beans/cookie/CookieManager;->waitForReadyState()V

    .line 275
    sput-object p0, Lcom/burstly/lib/network/beans/cookie/CookieManager;->sMemoryCookieStorage:Lcom/burstly/lib/network/beans/cookie/ICookieStorage;
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0

    .line 276
    monitor-exit v1

    return-void

    .line 273
    :catchall_0
    move-exception v0

    monitor-exit v1

    throw v0
.end method

.method static declared-synchronized setSQLiteCookieStorage(Lcom/burstly/lib/network/beans/cookie/ICookieStorage;)V
    .locals 2
    .parameter "newSQLiteCookieStorage"

    .prologue
    .line 259
    const-class v1, Lcom/burstly/lib/network/beans/cookie/CookieManager;

    monitor-enter v1

    :try_start_0
    invoke-static {}, Lcom/burstly/lib/network/beans/cookie/CookieManager;->checkManager()V

    .line 260
    invoke-static {}, Lcom/burstly/lib/network/beans/cookie/CookieManager;->waitForReadyState()V

    .line 261
    sput-object p0, Lcom/burstly/lib/network/beans/cookie/CookieManager;->sSQLiteCookieStorage:Lcom/burstly/lib/network/beans/cookie/ICookieStorage;
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0

    .line 262
    monitor-exit v1

    return-void

    .line 259
    :catchall_0
    move-exception v0

    monitor-exit v1

    throw v0
.end method

.method private static declared-synchronized waitForReadyState()V
    .locals 6

    .prologue
    .line 133
    const-class v2, Lcom/burstly/lib/network/beans/cookie/CookieManager;

    monitor-enter v2

    :goto_0
    :try_start_0
    sget-boolean v1, Lcom/burstly/lib/network/beans/cookie/CookieManager;->sIsReady:Z

    if-nez v1, :cond_0

    .line 134
    sget-object v1, Lcom/burstly/lib/network/beans/cookie/CookieManager;->LATCH:Ljava/util/concurrent/CountDownLatch;

    invoke-virtual {v1}, Ljava/util/concurrent/CountDownLatch;->await()V
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0
    .catch Ljava/lang/InterruptedException; {:try_start_0 .. :try_end_0} :catch_0

    goto :goto_0

    .line 137
    :catch_0
    move-exception v0

    .line 138
    .local v0, e:Ljava/lang/InterruptedException;
    :try_start_1
    invoke-static {}, Ljava/lang/Thread;->currentThread()Ljava/lang/Thread;

    move-result-object v1

    invoke-virtual {v1}, Ljava/lang/Thread;->interrupt()V

    .line 139
    sget-object v1, Lcom/burstly/lib/network/beans/cookie/CookieManager;->LOG:Lcom/burstly/lib/util/LoggerExt;

    const-string v3, "CookieManager"

    const-string v4, "Thread was interrupted while waiting for manager initialization!"

    const/4 v5, 0x0

    new-array v5, v5, [Ljava/lang/Object;

    invoke-virtual {v1, v3, v4, v5}, Lcom/burstly/lib/util/LoggerExt;->logWarning(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;
    :try_end_1
    .catchall {:try_start_1 .. :try_end_1} :catchall_0

    .line 141
    :cond_0
    monitor-exit v2

    return-void

    .line 133
    :catchall_0
    move-exception v1

    monitor-exit v2

    throw v1
.end method
